package yuejian_07.yuejian_07.model;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import yuejian_07.yuejian_07.base.RetrofitListenerTow;
import yuejian_07.yuejian_07.javabean.Comment;
import yuejian_07.yuejian_07.service.CommentService;

import static yuejian_07.yuejian_07.base.Constant.BASE_URL;

/**
 * Created by dell on 2017/11/3.
 */

public class CommentModel {
    private Retrofit retrofit;
    public CommentModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void getComments(int Show_id, final RetrofitListenerTow listener){
        CommentService commentService=retrofit.create(CommentService.class);
        Call call=commentService.getCommentsByShow(Show_id);
        Callback<List<Comment>> callback=new Callback<List<Comment>>(){
            @Override
            public void onResponse(Call<List<Comment>> call, Response<List<Comment>> response ){
                List<Comment> data=response.body();
                listener.onSuccessTow(data);//userId这里有问题
            }
            @Override
            public  void onFailure(Call<List<Comment>> call, Throwable t){
                listener.onFailTow();
            }
        };
        call.enqueue(callback);
    }
}
